package com.wc.AlgoOJ._思维.CT0111;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congege
 * @Description 光头强买股票
 * http://43.138.190.70:8888/p/CT0111
 * @Date Created in 2023/12/23-23:00
 */
public class Main {
    static FastReader in = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int m = in.nextInt();
        while (m-- > 0) {
            int ans = 0;
            int n = in.nextInt();
            int min = 10001;
            int num;
            while (n-- > 0) {
                num = in.nextInt();
                if (num > min) {
                    ans = Math.max(ans, num - min);
                } else {
                    min = num;
                }
            }
            out.println(ans);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }
}
